/**
 * created by 小卷毛, 2020/7/6
 * Copyright (c) 2020, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.zhiyou.aifeng.viewmodel

import com.lzg.extend.BaseResponse
import com.lzg.extend.jackson.JacksonConvert
import com.lzg.okrx.adapter.FlowableBody
import com.lzy.okgo.OkGo
import com.zhiyou.aifeng.common_ui.model.BaseUrl
import com.zhiyou.aifeng.common_ui.utils.applyFlowableSchedulers
import com.zhiyou.aifeng.common_ui.viewmodel.BaseViewModel
import com.zhiyou.aifeng.model.BrandData
import com.zhiyou.aifeng.model.MachineData

/**
 * 项目名称：Smart_Machine
 * 创建人：小卷毛
 * 创建时间：2020-07-06 17:50
 */
class MachineViewModel : BaseViewModel() {

    fun getMachineList(uid: String) =
        OkGo.post<BaseResponse<ArrayList<MachineData>>>(BaseUrl.brandList)
            .params(getParams("uid" to uid))
            .converter(object : JacksonConvert<BaseResponse<ArrayList<MachineData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }

    fun getBrandList(type: Int) =
        OkGo.post<BaseResponse<ArrayList<BrandData>>>(BaseUrl.brand)
            .params(
                getParams(
                    "type" to type,
                    "dict" to 1
                )
            )
            .converter(object : JacksonConvert<BaseResponse<ArrayList<BrandData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .doOnSubscribe { showLoading() }
            .doFinally { dismissLoading() }
            .map { it.data }

    fun getTypeList(type: String) =
        OkGo.post<BaseResponse<ArrayList<BrandData>>>(BaseUrl.brandType)
            .params(getParams("type" to type))
            .converter(object : JacksonConvert<BaseResponse<ArrayList<BrandData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .doOnSubscribe { showLoading() }
            .doFinally { dismissLoading() }
            .map { it.data }

    fun getNumList(type: Int, id: String) =
        OkGo.post<BaseResponse<ArrayList<BrandData>>>(BaseUrl.brandNum)
            .params(
                getParams(
                    "type" to type,
                    "id" to id
                )
            )
            .converter(object : JacksonConvert<BaseResponse<ArrayList<BrandData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .doOnSubscribe { showLoading() }
            .doFinally { dismissLoading() }
            .map { it.data }

}